package uy.com.antel.clientemdb;
import java.util.Properties;

import javax.jms.Destination;
import javax.jms.Queue;
import javax.jms.QueueConnection;
import javax.jms.QueueConnectionFactory;
import javax.jms.QueueSender;
import javax.jms.QueueSession;
import javax.jms.TextMessage;
import javax.naming.Context;
import javax.naming.InitialContext;

import org.hornetq.jms.client.HornetQQueue;

public class ClienteMDB {

    
    public static void main(String args[]) throws Exception    {        	    	

    	
    	Properties properties = new Properties();
 		properties.put(Context.INITIAL_CONTEXT_FACTORY,
 				"org.jnp.interfaces.NamingContextFactory");
 		properties.put(Context.URL_PKG_PREFIXES,
 				"org.jboss.naming:org.jnp.interfaces");
 		properties.put(Context.PROVIDER_URL, "jnp://127.0.0.1:1099");
 		InitialContext iniCtx = new InitialContext(properties);

     	Object tmp = iniCtx.lookup("ConnectionFactory");
     	QueueConnectionFactory qcf = (QueueConnectionFactory) tmp;
     	QueueConnection conn = qcf.createQueueConnection();
     	Queue que = (Queue) iniCtx.lookup("queue/j2ee_prueba_alta_editorial");
     	QueueSession session = conn.createQueueSession(false, QueueSession.AUTO_ACKNOWLEDGE);
     	conn.start();
    	
     	QueueSender send = session.createSender(que);        
       
        Destination dest = new HornetQQueue("queue/j2ee_prueba_alta_editorial");
              
        
        //Agrego Editoriales <nombre editorial>
        TextMessage tm = session.createTextMessage("Editorial1");
        tm.setJMSReplyTo(dest );
        send.send(tm);
     
        tm = session.createTextMessage("Editorial2");
        tm.setJMSReplyTo(dest );
        send.send(tm);
        
        tm = session.createTextMessage("Editorial1"); /// nombre duplicado
        tm.setJMSReplyTo(dest );
        send.send(tm);
        tm = session.createTextMessage("Editorial3");
        tm.setJMSReplyTo(dest );
        send.send(tm);
       
        
        //Publicaciones <nombre editorial> <nombre libro> <ISBN>
        
        que = (Queue) iniCtx.lookup("queue/j2ee_prueba_alta_publicacion");
        session = conn.createQueueSession(false, QueueSession.AUTO_ACKNOWLEDGE);
     	conn.start();
    	
     	send = session.createSender(que);        
            
        dest = new HornetQQueue("queue/j2ee_prueba_alta_publicacion");
        
        tm = session.createTextMessage("Editorial1 Escandalo 1653242516");
        tm.setJMSReplyTo(dest );
        send.send(tm);
        
        tm = session.createTextMessage("Editorial3 Compiladores 1653242588");
        tm.setJMSReplyTo(dest );
        send.send(tm);
        
        tm = session.createTextMessage("Editorial1 Escandalo 1653242517");
        tm.setJMSReplyTo(dest );
        send.send(tm);
        
        tm = session.createTextMessage("Editorial1 Escandalo 1653242517"); //  isbn duplicado
        tm.setJMSReplyTo(dest );
        send.send(tm);
        
        
        send.close();
        conn.stop();
        session.close();
        conn.close();
    }
    
    
    
    
}
